<template>
  <div class="table-wrapper">
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">校区：</span>
        <el-select size="mini" v-model="params.is_xq" placeholder="请选择校区" @change="getBuilde" clearable>
          <el-option v-for="item in xqList" :key="item.text" :label="item.text" :value="item.value"></el-option>
        </el-select>
      </div>
      <div class="search-wrapper">
        <span class="label">楼宇：</span>
        <el-select
          v-model="params.builde_id"
          size="mini"
          class="large-select"
          collapse-tags
          clearable
          :disabled="!params.is_xq"
          placeholder="请选择楼宇">
          <el-option
            v-for="item in buildingList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </div>
      <div class="search-wrapper">
        <span class="label">关键字：</span>
        <el-input v-model="params.name" size="mini" class="common-input" placeholder="请输入关键字"></el-input>
      </div>
    </div>
    <div class="search-container">
      <div class="search-wrapper">
        <span class="label">开始时间：</span>
        <el-date-picker
          size="mini"
          v-model="params.start_time"
          :type="'year'"
          :value-format="'yyyy'"
          placeholder="选择开始时间"
        >
        </el-date-picker>
      </div>
      <div class="search-wrapper">
        <span class="label">结束时间：</span>
        <el-date-picker
          size="mini"
          v-model="params.end_time"
          :type="'year'"
          :value-format="'yyyy'"
          placeholder="选择结束时间"
        >
        </el-date-picker>
      </div>
      <div class="search-wrapper">
        <el-button @click="getProject" icon="el-icon-search" size="mini" >查询</el-button>
      </div>
    </div>
    <el-table
      :data="data"
      border
      height="calc(100% - 160px)"
      style="width: 100%">
      <el-table-column
        prop="builde_id"
        label="项目地点">
        <template slot-scope="scope">
          {{ buildingMap[scope.row.builde_id] || scope.row.builde_id }}
        </template>
      </el-table-column>
      <el-table-column
        prop="name"
        label="工程名称">
      </el-table-column>
      <el-table-column
        prop="category"
        label="项目类别">
      </el-table-column>
      <el-table-column
        prop="completion_time"
        label="竣工时间(年)">
        <template slot-scope="scope">
          {{ scope.row.completion_time.substr(0,4) }}
        </template>
      </el-table-column>
      <el-table-column
        prop="project_leader"
        label="项目负责人">
      </el-table-column>
      <el-table-column
        prop="site_leader"
        label="现场负责人">
      </el-table-column>
      <el-table-column
        prop="const_unit"
        label="施工单位">
      </el-table-column>
      <el-table-column
        prop="const_contact"
        label="施工单位负责人">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import portal from '@/api/portal'

export default {
  name: 'GcList',
  data () {
    return {
      params: {
        builde_id: null,
        name: null,
        start_time: null,
        end_time: null
      },
      xqList: [
        {
          text: '中关村',
          value: 1
        },
        {
          text: '良乡',
          value: 2
        }
      ],
      buildingList: [],
      buildingMap: {},
      data: []
    }
  },
  created () {
  },
  computed: {
  },
  mounted () {
  },
  methods: {
    // 工程列表
    async getProject () {
      const params = this.params
      if (!this.params.is_xq) {
        this.$message.warning('请选择校区')
        return
      }
      if (!this.params.builde_id) {
        this.$message.warning('请选择楼宇')
        return
      }
      const result = await portal.getProject(params)
      if (result.data) {
        this.data = result.data
      }
    },
    // 根据校区获取楼宇
    async getBuilde () {
      const params = {
        is_xq: this.params.is_xq
      }
      const result = await portal.getBuilde(params)
      if (result.data) {
        result.data.forEach(e => {
          e.value = e.id
          e.label = e.builde_name
          e.check = false
          this.buildingMap[e.value] = e.label
        })
        this.buildingList = result.data
      }
    },
    changePage (val) {
      this.params.page = val
      this.getBusOrder()
    }
  }
}
</script>

<style scoped lang="scss">

</style>
